﻿using EasyTest.Shared.TestAttribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;


namespace ZLGCANoptimize
{
    public class Part4
    {
        //static ZLGCANHelper zLGCANHelper = null;
        //static List<ZCAN_Receive_Data> zCAN_Receive_Datas = null;
        [ExposedMethodAttribute("")]
        public bool 读取NADIPADDRESS1(int 通道, out string NadIP, out int SN字节, out string 信息)
        {
#if ELO20240927
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 06 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#else
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 06 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#endif
        }
        [ExposedMethodAttribute("")]
        public bool 读取NADIPADDRESS1B006(int 通道, out string NadIP, out int SN字节, out string 信息)
        {
#if ELO20240927
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 06 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#else
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 06 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#endif
        }
        [ExposedMethodAttribute("")]
        public bool 读取NADIPADDRESS2B007(int 通道, out string NadIP, out int SN字节, out string 信息)
        {
#if ELO20240927
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 07 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#else
            信息 = "";
            NadIP = "";
            SN字节 = NadIP.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 07 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("22"))
                    {
                        ok22 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 6) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                if (!ok10 || !ok21 || !ok22)
                {
                    信息 = string.Join("\n", datas);
                    return false;
                }

                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join("\n", hexValues);

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                NadIP = "";
                return false;
            }
            SN字节 = NadIP.Trim().Length;
            return true;
#endif
        }

        [ExposedMethodAttribute("")]
        public bool 读GNSS基本信息(int 通道, out string GNSS基本信息, out string 信息, out string 经纬度)
        {
#if ELO20240927
            信息 = "";
            GNSS基本信息 = "";
            经纬度 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 04 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                string[] 纬度 = new string[4];
                string[] 经度 = new string[4];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 5) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                信息 = string.Join("\n", datas);
                if (!ok10 || !ok21)
                {
                    return false;
                }
                纬度 = hexValues.ToList().GetRange(0, 4).ToArray();
                经度 = hexValues.ToList().GetRange(0, 4).ToArray();
                经纬度 = "纬度:" + string.Join("", 纬度) + "经度:" + string.Join("", 经度);
                //foreach (String hex in hexValues)
                //{
                //    int value = Convert.ToInt32(hex, 16);
                //    string stringValue = Char.ConvertFromUtf32(value);
                //    hexValues0 += stringValue;
                //}
                return true;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                GNSS基本信息 = "";
                return false;
            }
            return true;
#else
            信息 = "";
            GNSS基本信息 = "";
            经纬度 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 04 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                string[] 纬度 = new string[4];
                string[] 经度 = new string[4];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 5) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                信息 = string.Join("\n", datas);
                if (!ok10 || !ok21)
                {
                    return false;
                }
                纬度 = hexValues.ToList().GetRange(0, 4).ToArray();
                经度 = hexValues.ToList().GetRange(0, 4).ToArray();
                经纬度 = "纬度:" + string.Join("", 纬度) + "经度:" + string.Join("", 经度);
                //foreach (String hex in hexValues)
                //{
                //    int value = Convert.ToInt32(hex, 16);
                //    string stringValue = Char.ConvertFromUtf32(value);
                //    hexValues0 += stringValue;
                //}
                return true;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                GNSS基本信息 = "";
                return false;
            }
            return true;
#endif
        }

        [ExposedMethodAttribute("")]
        public bool 读GNSS扩展信息(int 通道, out string GNSS基本信息, out string 信息)
        {
#if ELO20240927
            信息 = "";
            GNSS基本信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 05 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                string[] 纬度 = new string[4];
                string[] 经度 = new string[4];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 5) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                信息 = string.Join("\n", datas);
                if (!ok10 || !ok21)
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                GNSS基本信息 = "";
                return false;
            }
            return true;
#else
            信息 = "";
            GNSS基本信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                zLGCANHelper.SentData(通道, 0x761, "03 22 B0 05 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 5, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                string[] hexValues = new string[15];
                string[] 纬度 = new string[4];
                string[] 经度 = new string[4];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i == 0 || i > 5) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                var hexValues0 = "";
                信息 = string.Join("\n", datas);
                if (!ok10 || !ok21)
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                GNSS基本信息 = "";
                return false;
            }
            return true;
#endif
        }
    }
}
